{include file="public/header" /}
<nav class="breadcrumb">
    <i class="Hui-iconfont">&#xe67f;</i> 首页
    <span class="c-gray en">&gt;</span> 文章管理
    <span class="c-gray en">&gt;</span> 文章编辑
    <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a>
</nav>
<link rel="stylesheet" type="text/css" href="/static/wangEditor/release/wangEditor.min.css"/>
<script type="text/javascript" src="/static/wangEditor/release/wangEditor.min.js"></script>
<form action="" method="post" class="form form-horizontal" id="form-add">
    <div class="row cl" style="width: 100%">
        <label class="form-label col-xs-2 col-sm-2"><span class="c-red">*</span>标题：</label>
        <div class="formControls col-xs-8 col-sm-9">
            <input type="text" class="input-text" value="{$row.title|default=''}" placeholder="" id="title" name="title" maxlength="10">
        </div>
    </div>
    <div class="row cl" style="width: 100%">
        <label class="form-label col-xs-2 col-sm-2"><span class="c-red">*</span>介绍：</label>
        <div class="formControls col-xs-8 col-sm-9">
            <input type="text" class="input-text" value="{$row.introduce|default=''}" placeholder="" id="introduce" name="introduce" maxlength="10">
        </div>
    </div>

    <div class="row cl" style="width: 100%">
        <label class="form-label col-xs-2 col-sm-2"><span class="c-red">*</span>类型：</label>
        <div class="formControls col-xs-8 col-sm-9">
            <select name="type" class="select">
                <option value="0">请选择类型</option>
                {foreach $types as $v}
                {if $v.id == $row.type}
                <option value="{$v.id}" selected>{$v.title}</option>
                {else/}
                <option value="{$v.id}">{$v.title}</option>
                {/if}

                {/foreach}
            </select>
        </div>

    </div>

    <div id="div1" style="padding: 20px"></div>

    <div class="row cl" style="width: 100%">
        <textarea name="content" id="text1" style="width:100%; height:200px;display: none">{$row.content|default=''}</textarea>
        <div style="width: 100%;text-align: center">
            <input type="hidden" value="{$row.id|default=''}" name="id">
            <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
        </div>
    </div>
</form>

<!--我在这做了修改，给了一个name属性，方便后端接收值-->

{include file="public/footer" /}
<script>
    var E = window.wangEditor
    var editor = new E('#div1')
    var $text1 = $('#text1')
    editor.customConfig.onchange = function (html) {
        // 监控变化，同步更新到 textarea
        $text1.val(html)
    }
    editor.customConfig.uploadImgMaxLength = 1
    editor.customConfig.uploadImgMaxSize = 10 * 1024 * 1024
    editor.customConfig.uploadImgServer = '/shop/uploadFieldByEdit'
    editor.customConfig.uploadFileName = 'file'
    editor.customConfig.uploadImgHeaders = {
        'Accept': 'text/x-json'
    }
    editor.customConfig.uploadImgTimeout = 3000

    editor.create()
    editor.txt.html($text1.text())
    $("#form-add").validate({
        rules:{
            username:{
                required:true,
                maxlength:50
            },
        },
        onkeyup:false,
        focusCleanup:true,
        success:"valid",
        submitHandler:function(form){
            $(form).ajaxSubmit({
                success:function(data){
                    console.log(data);
                    if(data.status == 'y'){
                        layer.msg("操作成功",{icon:1,time:1000,shade: [0.3, '#000']},function(){
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.location.reload();
                            parent.layer.close(index);
                        });
                    }else{
                        layer.msg(data.info,{icon:2,time:1000,shade: [0.3, '#000']});
                    }
                },
                error:function(error){
                    layer.msg('系统发生了错误',{icon:2,time:3000,shade: [0.5, '#FF0000']});
                }
            });

        }
    });
</script>
